<template>
	<div class="pages">
		<el-tabs v-model="activeName" @tab-click="handleClick" v-if="$store.state.userType!=4">
			<el-tab-pane label="全部订单" name="99"></el-tab-pane>
			<template v-if="$store.state.userType==3">
				<el-tab-pane label="需求待接单" name="2"></el-tab-pane>
				<el-tab-pane label="工厂确认中" name="6"></el-tab-pane>
				<el-tab-pane label="订单待发货" name="7"></el-tab-pane>
			</template>
			<template v-else>
				<el-tab-pane label="需求待审核" name="0"></el-tab-pane>
				<el-tab-pane label="需求待派单" name="1"></el-tab-pane>
				<el-tab-pane label="创制券审核" name="4"></el-tab-pane>
			</template>
		</el-tabs>
		<el-form :inline="true" size="small" :model="dataForm" label-width="90px">
			<el-form-item>
				<el-button type="primary" @click="addOrUpdateHandle()"
					v-if="$hasPermission('api/order/post')">新增</el-button>
			</el-form-item>
			<el-form-item label="订单编号:">
				<el-input v-model="dataForm.order_sn" placeholder="请输入" clearable></el-input>
			</el-form-item>
			<el-form-item label="需求类型:">
				<el-select v-model="dataForm.level" placeholder="请选择" clearable>
					<el-option v-for="item in xqList" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="订单状态：">
				<el-select v-model="dataForm.status" placeholder="请选择" clearable>
					<el-option v-for="item in stateList" :key="item.status" :label="item.title" :value="item.status">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="企业名称:" v-if="$store.state.userType==3">
				<el-input v-model="dataForm.corp" placeholder="请输入" clearable></el-input>
			</el-form-item>
			<el-form-item label="需求名称:">
				<el-input v-model="dataForm.title" placeholder="请输入" clearable></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="getDataList">搜索</el-button>
			</el-form-item>
			<el-form-item v-if="$hasPermission('api/order/all_adopt')">
				<el-button @click="all_shenhe()">需求审核</el-button>
			</el-form-item>
			<el-form-item v-if="$hasPermission('api/order/all_reject')">
				<el-button @click="all_bohui()">需求驳回</el-button>
			</el-form-item>
			<el-form-item v-if="$hasPermission('api/order/all_paidan')">
				<el-button @click="paidan()">需求派单</el-button>
			</el-form-item>
			<!-- 			<el-form-item>
				<el-button>创制券审核</el-button>
			</el-form-item>
			<el-form-item>
				<el-button>创制券驳回</el-button>
			</el-form-item> -->
			<el-form-item>
				<el-button @click="exports">批量导出</el-button>
			</el-form-item>
		</el-form>
		<el-table :data="dataList" v-loading="dataListLoading" @selection-change="dataListSelectionChangeHandle" border
			style="width: 100%" header-align="center">
			<el-table-column type="selection" width="55" align="center">
			</el-table-column>
			<el-table-column type="index" width="55" align="center" label="序号">
			</el-table-column>
			<el-table-column prop="order_sn" align="center" label="订单号">
			</el-table-column>
			<el-table-column prop="title" align="center" label="需求名称">
			</el-table-column>
			<el-table-column prop="corp" align="center" label="企业名称">
			</el-table-column>
			<el-table-column prop="level" align="center" label="需求类型">
				<template slot-scope="scope">
					<span v-if="scope.row.level==1">设计研发需求</span>
					<span v-if="scope.row.level==2">物资采购需求</span>
					<span v-if="scope.row.level==3">加工制造需求</span>
				</template>
			</el-table-column>
			<el-table-column prop="create_time" align="center" label="创建时间">
			</el-table-column>
			<el-table-column prop="status" align="center" label="订单状态" :formatter="formatter">
			</el-table-column>
			<el-table-column prop="factory_name" align="center" label="派单工厂">
			</el-table-column>
			<el-table-column prop="remarks" align="center" label="备注">
			</el-table-column>
			<el-table-column align="center" label="操作" width="200">
				<template slot-scope="scope" class="www">
					<el-button type="text" @click="showDetail(scope.row)"
						v-if="$hasPermission('api/order/detail')">查看详情</el-button>
					<el-button type="text" @click="edit(scope.row)"
						v-if="$hasPermission('api/order/edit_xuqiu') && ($store.state.userType==1)">编辑</el-button>
					<el-button type="text"
						v-if="($store.state.userType==4 || $store.state.userType==2) && (scope.row.status=='0' || scope.row.status=='-1')"
						@click="addOrUpdateHandle(scope.row.order_id)">需求编辑</el-button>
					<el-button type="text" @click="zuofei(scope.row)"
						v-if="($store.state.userType==1 || $store.state.userType==2) && scope.row.status!='-4'">作废</el-button>
					<el-button type="text" @click="shenhe(scope.row)"
						v-if="scope.row.status==0 && $hasPermission('api/order/setField')">审核通过</el-button>
					<el-button type="text" @click="bohui(scope.row)"
						v-if="scope.row.status==0 && $hasPermission('api/order/reject')">驳回</el-button>
					<el-button type="text" @click="paidan(scope.row)"
						v-if="scope.row.status==1 && $hasPermission('api/order/paidan')">派单</el-button>
					<el-button type="text" @click="paidan(scope.row)"
						v-if="scope.row.status=='-2' && $hasPermission('api/order/paidan')">重新派单</el-button>
					<el-button type="text" @click="dkpz(scope.row)"
						v-if="scope.row.status==5 && $hasPermission('api/order/payment_voucher')">上传打款凭证</el-button>
					<el-button type="text" @click="dkqr(scope.row)"
						v-if="scope.row.status==6 && $hasPermission('api/order/payconfirm')">打款确认</el-button>
					<el-button type="text" @click="fahuo(scope.row)"
						v-if="scope.row.status==7 && $hasPermission('api/order/delivery')">订单发货</el-button>
					<!-- 工厂端接单 -->
					<el-button type="text" @click="jiedan(scope.row)"
						v-if="scope.row.status==2 && ($hasPermission('api/order/jiedan') || $store.state.userType==1 || $store.state.userType==2)">接单</el-button>
					<el-button type="text" @click="judan(scope.row)"
						v-if="scope.row.status==2 && ($hasPermission('api/order/judan') || $store.state.userType==1 || $store.state.userType==2)">拒单</el-button>
					<!-- 企业端确认收货 -->
					<el-button type="text" @click="ok_sh(scope.row)"
						v-if="scope.row.status==8 && ($hasPermission('api/order/shouhuo')|| $store.state.userType==1 || $store.state.userType==2)">确认收货</el-button>
					<el-button type="text" @click="add_czq(scope.row)"
						v-if="scope.row.status==3 && $hasPermission('api/order/coupons')">申请创制券</el-button>
					<el-button type="text" @click="sh_czq(scope.row)"
						v-if="($store.state.userType==1 || $store.state.userType==2) && scope.row.status==4">创制券审核</el-button>
					<el-button type="text" @click="bh_czq(scope.row)"
						v-if="($store.state.userType==1 || $store.state.userType==2) && scope.row.status==4">创制券驳回</el-button>
					<el-button type="text" @click="edit_czq(scope.row)"
						v-if="($store.state.userType==1 || $store.state.userType==2 || $store.state.userType==4) && (scope.row.status==4 || scope.row.status=='-3')">创制券编辑
					</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
			layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
			@current-change="pageCurrentChangeHandle">
		</el-pagination>
		<el-dialog title="派单到工厂" :visible.sync="dialogVisible_paidan" :before-close="handleClose" width="640px">
			<div>
				<table width="100%" class="table">
					<tr>
						<th style="width: 60%;">工厂名称</th>
						<th style="width: 40%;">操作</th>
					</tr>
					<tr v-for="item in factList" :key="item.id">
						<td>{{item.name}}</td>
						<td>
							<el-button type="text" @click="paidan_submit2(item.id)">派单</el-button>
						</td>
					</tr>
				</table>
			</div>
		</el-dialog>
		<el-dialog title="上传打款凭证" :visible.sync="dialogVisible_dkpz" :before-close="handleClose_kdpz" width="640px">
			<div>
				<el-form size="small" label-width="80px" style="padding-right: 150px;">
					<el-form-item label="打款凭证" required>
						<uploadImg :limit="1" url="/api/publics/upload" title="支持图片或pdf格式" accept="image/*,.pdf"
							@saveImgs="saveImg_dkpz" size="10">
						</uploadImg>
					</el-form-item>
					<el-form-item label="打款信息">
						<el-input v-model="dataForm_dkpz.payment_text" placeholder="请输入打款信息"></el-input>
					</el-form-item>
				</el-form>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="handleClose_kdpz()" size="small">取 消</el-button>
				<el-button type="primary" size="small" @click="submitForm_dkpz">确 定</el-button>
			</span>
		</el-dialog>

		<el-dialog title="打款信息" :visible.sync="dialogVisible_dkqr" :before-close="handleClose_dkqr" width="640px">
			<div>
				<el-form size="small" label-width="80px">
					<el-form-item label="打款凭证">
						<el-button type="primary" @click="look_dkpz">点击查看</el-button>
					</el-form-item>
				</el-form>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="handleClose_dkqr()" size="small">取 消</el-button>
				<el-button type="primary" size="small" @click="submitForm_dkqr">确 定</el-button>
			</span>
		</el-dialog>

		<el-dialog title="发货信息" :visible.sync="dialogVisible_fhxx" :before-close="handleClose_fhxx" width="640px">
			<div>
				<el-form size="small" label-width="80px" :model="dataForm_fhxx" ref="dataForm_fhxx">
					<el-form-item label="发货信息" prop="content">
						<el-input type="textarea" v-model="dataForm_fhxx.content"></el-input>
					</el-form-item>
					<el-form-item label="发货附件">
						<uploadImg :limit="1" url="/api/publics/upload" title="支持图片或pdf格式" accept="image/*,.pdf"
							@saveImgs="saveImg_fhfj" size="10">
						</uploadImg>
					</el-form-item>
				</el-form>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="handleClose_fhxx()" size="small">取 消</el-button>
				<el-button type="primary" size="small" @click="submitForm_fhxx">确 定</el-button>
			</span>
		</el-dialog>

		<el-dialog title="申请创制券" :visible.sync="dialogVisible_czq" :before-close="handleClose_czq" width="640px">
			<div>
				<el-form :model="dataForm_czq" size="small" label-width="150px" :rules="rules2" ref="dataForm_czq"
					style="padding-right: 100px;">
					<el-form-item label="企业名称" v-if="!dataForm_czq.id">
						<el-input v-model="dataForm_czq.corp" disabled></el-input>
					</el-form-item>
					<el-form-item label="需求类型" v-if="!dataForm_czq.id">
						<el-input v-model="dataForm_czq.level_name" disabled></el-input>
					</el-form-item>
					<el-form-item label="需求名称" v-if="!dataForm_czq.id">
						<el-input v-model="dataForm_czq.title" disabled></el-input>
					</el-form-item>
					<el-form-item label="工厂名称" v-if="!dataForm_czq.id">
						<el-input v-model="dataForm_czq.factory" disabled></el-input>
					</el-form-item>
					<el-form-item label="合同金额(元)" prop="hetong_num">
						<el-input type="number" v-model="dataForm_czq.hetong_num" placeholder="请输入合同金额(元)"></el-input>
					</el-form-item>
					<el-form-item label="服务费用(元)" prop="fuwu_num">
						<el-input type="number" v-model="dataForm_czq.fuwu_num" placeholder="请输入服务费用(元)"></el-input>
					</el-form-item>
					<el-form-item label="创制券申请额度(元)" prop="coupons_num">
						<el-input type="number" v-model="dataForm_czq.coupons_num" placeholder="创制券申请额度(元)"></el-input>
						<span style="font-size: 12px;color: #999;">创制券申请额度应小于等于服务费用</span>
					</el-form-item>
					<el-form-item label="合同文件" prop="thumb">
						<uploadImg :limit="1" url="/api/publics/upload" title="支持图片或pdf格式" accept="image/*,.pdf"
							@saveImgs="saveImg_czq" size="10" :img="imgList_czq">
						</uploadImg>
					</el-form-item>
				</el-form>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="handleClose_czq()" size="small">取 消</el-button>
				<el-button type="primary" size="small" @click="submitForm_czq" v-if="!dataForm_czq.id">确 定</el-button>
				<el-button type="primary" size="small" @click="submitForm_czq2" v-else>确 定</el-button>
			</span>
		</el-dialog>

		<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
	</div>
</template>

<script>
	import mixinViewModule from '@/mixins/view-module'
	import AddOrUpdate from './add-or-update'
	import uploadImg from '@/components/uploadImg.vue'
	export default {
		mixins: [mixinViewModule],
		data() {
			const img_czq = (rule, value, callback) => {
				if (!this.dataForm_czq.thumb) {
					callback(new Error('请上传合同文件'))
				} else {
					callback()
				}
			}
			return {
				mixinViewModuleOptions: {
					getDataListURL: '/api/order/getList',
					getDataListIsPage: true,
					deleteURL: '/tbcasegroup',
					deleteIsBatch: true,
					createdIsNeed: true,
				},
				dialogVisible_paidan: false,
				dialogVisible_dkpz: false,
				dialogVisible_dkqr: false,
				dialogVisible_fhxx: false,
				dialogVisible_czq: false,
				dataForm: {
					order_sn: '',
					status: '',
					level: '',
					corp: '',
					title: '',
				},
				dataForm_dkpz: {
					id: '',
					thumb: '',
					payment_text: '',
				},
				dataForm_dkqr: {
					id: ''
				},
				dataForm_fhxx: {
					id: '',
					content: '',
					thumb: '',
				},
				dataForm_czq: {
					id: '',
					is_post: 1,
					hetong_num: '',
					fuwu_num: '',
					coupons_num: '',
					thumb: '',
					corp: '',
					level_name: '',
					factory: '',
					title: '',
				},
				rules2: {
					hetong_num: [{
						required: true,
						message: '请输入合同金额',
						trigger: 'blur'
					}],
					fuwu_num: [{
						required: true,
						message: '请输入服务费用',
						trigger: 'blur'
					}],
					coupons_num: [{
						required: true,
						message: '请输入创制券申请额度',
						trigger: 'blur'
					}],
					thumb: [{
						required: true,
						message: '请上传合同文件',
						validator: img_czq,
						trigger: 'change'
					}]
				},
				stateList: [],
				factList: [],
				pd_list: [],
				xqList: [{
					value: '1',
					label: '设计研发需求'
				}, {
					value: '2',
					label: '物资采购需求'
				}, {
					value: '3',
					label: '加工制造需求'
				}],
				activeName: '99',
				imgList_czq: '',
			}
		},
		components: {
			AddOrUpdate,
			uploadImg
		},
		methods: {
			showDetail(row) {
				this.$router.push({
					path: '/order/detail',
					query: {
						id: row.order_id
					}
				})
			},
			edit(row) {
				this.$router.push({
					path: '/order/edit',
					query: {
						id: row.order_id
					}
				})
			},
			// edit2(row) {
			// 	this.$router.push({
			// 		path: '/order/edit2',
			// 		query: {
			// 			id: row.order_id
			// 		}
			// 	})
			// },
			handleClick(e) {
				// console.log(e)
				if (e.name == '99') {
					this.dataForm.status = ''
				} else {
					this.dataForm.status = Number(e.name)
				}
				this.getDataList()
			},
			getStateList() {
				this.$http.post('/api/publics/status_list', {}).then(res => {
					this.stateList = res.result
				})
			},
			getFactList() {
				this.$http.post('/api/publics/getfactorylist', {
					page: 1,
					limit: 1000
				}).then(res => {
					this.factList = res.result.data
				})
			},
			//审核通过
			all_shenhe() {
				if (this.dataListSelections.length <= 0) {
					return this.$message.warning("请勾选数据！")
				}
				this.$confirm('确定批量审核通过选中的需求吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let ids = this.dataListSelections.map(res => res['order_id'])
					this.$loading()
					this.$http.post('/api/order/all_adopt', {
						ids: ids.join(","),
					}).then(res => {
						this.$closeLoading()
						this.$message.success(res.msg)
						this.getDataList()
					})
				}).catch(() => {});

			},
			shenhe(row) {
				this.$confirm('是否审核通过?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$loading()
					this.$http.post('/api/order/setField', {
						id: row.order_id,
						value: 1
					}).then(res => {
						this.$closeLoading()
						this.$message.success(res.msg)
						this.getDataList()
					})
				}).catch(() => {});
			},
			jiedan(row) {
				this.$confirm('是否确认接单?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$loading()
					this.$http.post('/api/order/setField', {
						id: row.order_id,
						value: 3
					}).then(res => {
						this.$closeLoading()
						this.$message.success(res.msg)
						this.getDataList()
					})
				}).catch(() => {});
			},
			judan(row) {
				this.$prompt('拒单原因', '提示', {
					showInput: true,
					inputType: 'textarea',
					inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
					inputErrorMessage: '拒单原因不能为空!',
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then((param) => {
					this.$loading()
					let ids = this.dataListSelections.map(res => res['order_id'])
					this.$http.post('/api/order/reject', {
						id: row.order_id,
						cause: param.value,
						type: '-2',
					}).then(res => {
						this.$closeLoading()
						this.$message.success(res.msg)
						this.getDataList()
					})
				}).catch(() => {});
			},
			//驳回
			all_bohui(row) {
				if (this.dataListSelections.length <= 0) {
					return this.$message.warning("请勾选数据！")
				}
				this.$prompt('驳回原因', '提示', {
					showInput: true,
					inputType: 'textarea',
					inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
					inputErrorMessage: '驳回原因不能为空!',
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then((param) => {
					this.$loading()
					let ids = this.dataListSelections.map(res => res['order_id'])
					this.$http.post('/api/order/all_reject', {
						ids: ids.join(","),
						cause: param.value,
						type: '-1',
					}).then(res => {
						this.$closeLoading()
						this.$message.success(res.msg)
						this.getDataList()
					})
				}).catch(() => {});
			},
			bohui(row) {
				this.$prompt('驳回原因', '提示', {
					showInput: true,
					inputType: 'textarea',
					inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
					inputErrorMessage: '驳回原因不能为空!',
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then((param) => {
					this.$loading()
					this.$http.post('/api/order/reject', {
						id: row.order_id,
						cause: param.value,
						type: '-1',
					}).then(res => {
						this.$closeLoading()
						this.$message.success(res.msg)
						this.getDataList()
					})
				}).catch(() => {});
			},
			//派单到工厂
			paidan(row) {
				if (!row) {
					if (this.dataListSelections.length <= 0) {
						return this.$message.warning("请勾选数据！")
					} else {
						this.paidan_submit(this.dataListSelections)
					}
				} else {
					this.paidan_submit([row])
				}
			},
			paidan_submit(row) {
				this.pd_list = row
				this.dialogVisible_paidan = true
			},
			paidan_submit2(id) {
				let ids = this.pd_list.map(res => res['order_id'])
				let url = ''
				if (ids.length > 1) {
					url = '/api/order/all_paidan'
				} else {
					url = '/api/order/paidan'
				}
				let data1 = {
					id: ids.join(","),
					factory_id: id,
				}
				let data2 = {
					ids: ids.join(","),
					factory_id: id,
				}
				this.$loading()
				this.$http.post(url, ids.length > 1 ? data2 : data1).then(res => {
					this.$message({
						message: res.msg,
						type: "success",
						duration: 1000,
						onClose: () => {
							this.$closeLoading()
							this.dialogVisible_paidan = false
							this.getDataList()
							this.pd_list = []
						}
					});
				})
			},
			add_czq(row) {
				this.$nextTick(() => {
					this.$loading()
				})
				this.dataForm_czq.id = row.order_id
				this.$http.post('/api/order/coupons', {
					id: row.order_id
				}).then(res => {
					this.$closeLoading()
					this.dataForm_czq.corp = res.result.corp
					this.dataForm_czq.level_name = res.result.level_name
					this.dataForm_czq.factory = res.result.factory
					this.dataForm_czq.title = res.result.title
				})
				this.dialogVisible_czq = true
			},
			edit_czq(row) {
				this.$nextTick(() => {
					this.$loading()
				})
				this.$http.post('/api/order/edit_coupons', {
					id: row.order_id
				}).then(res => {
					this.$closeLoading()
					this.dataForm_czq = {
						...this.dataForm_czq,
						...res.result
					}
					if (this.dataForm_czq.thumb) {
						this.imgList_czq = {
							name: '合同文件',
							url: process.env.VUE_APP_BASE_API + this.dataForm_czq.thumb
						}
					}
					this.dialogVisible_czq = true
				})

			},
			sh_czq(row) {
				this.$confirm('是否审核通过创制券？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {

					this.$loading()
					this.$http.post('/api/order/setField', {
						id: row.order_id,
						value: 5
					}).then(res => {
						this.$closeLoading()
						this.$store.dispatch("userCzqAction")
						this.$message({
							message: res.msg,
							type: "success",
							duration: 1500,
							onClose: () => {
								this.getDataList()
							}
						});
					})
				}).catch(() => {});
			},
			bh_czq(row) {
				this.$confirm('是否驳回创制券？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {

					this.$prompt('驳回原因', '提示', {
						showInput: true,
						inputType: 'textarea',
						inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
						inputErrorMessage: '驳回原因不能为空!',
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then((param) => {
						this.$loading()
						this.$http.post('/api/order/reject', {
							id: row.order_id,
							cause: param.value,
							type: '-3',
						}).then(res => {
							this.$closeLoading()
						this.$message({
							message: res.msg,
							type: "success",
							duration: 1500,
							onClose: () => {
								this.getDataList()
							}
						});
						})
					}).catch(() => {});
				}).catch(() => {});
			},
			handleClose() {
				this.dialogVisible_paidan = false
			},
			handleClose_kdpz() {
				this.dialogVisible_dkpz = false
			},
			handleClose_dkqr() {
				this.dialogVisible_dkqr = false
			},
			handleClose_fhxx() {
				this.dialogVisible_fhxx = false
			},
			handleClose_czq() {
				this.dialogVisible_czq = false
			},
			dkpz(row) {
				this.dialogVisible_dkpz = true
				this.dataForm_dkpz.id = row.order_id
			},
			saveImg_dkpz(e) {
				this.dataForm_dkpz.thumb = e
			},
			saveImg_fhfj(e) {
				this.dataForm_fhxx.thumb = e
			},
			saveImg_czq(e) {
				this.dataForm_czq.thumb = e
			},
			submitForm_dkpz() {
				if (!this.dataForm_dkpz.thumb) {
					return this.$message.error("请上传打款凭证！")
				}
				this.$loading()
				this.$http.post('/api/order/payment_voucher', this.dataForm_dkpz).then(res => {
					this.$closeLoading()
					this.$message({
						message: res.msg,
						type: "success",
						duration: 1000,
						onClose: () => {
							this.getDataList()
							this.dialogVisible_dkpz = false
							this.fileList1 = []
							this.dataForm_dkpz = {
								id: '',
								thumb: '',
							}
						}
					});
				})
			},
			dkqr(row) {
				this.dialogVisible_dkqr = true
				this.dataForm_dkqr.id = row.order_id
			},
			look_dkpz() {
				this.$http.post('/api/order/payconfirm', {
					id: this.dataForm_dkqr.id,
				}).then(res => {
					// console.log(res)
					window.open(process.env.VUE_APP_BASE_API + res.result)
				})
			},
			submitForm_dkqr() {
				this.$loading()
				this.$http.post('/api/order/setField', {
					id: this.dataForm_dkqr.id,
					value: 7
				}).then(res => {
					this.$message({
						message: res.msg,
						type: "success",
						duration: 1000,
						onClose: () => {
							this.$closeLoading()
							this.getDataList()
							this.dialogVisible_dkqr = false
							this.dataForm_dkqr = {
								id: '',
							}
						}
					});
				})
			},
			fahuo(row) {
				this.dialogVisible_fhxx = true
				this.dataForm_fhxx.id = row.order_id
			},
			submitForm_fhxx() {
				if (!this.dataForm_fhxx.content) {
					return this.$message.warning("请填写发货信息！")
				}
				if (!this.dataForm_fhxx.thumb) {
					return this.$message.warning("请上传发货附件！")
				}
				this.$loading()
				this.$http.post('/api/order/delivery', {
					id: this.dataForm_fhxx.id,
					content: this.dataForm_fhxx.content,
					thumb: this.dataForm_fhxx.thumb,
				}).then(res => {
					this.$closeLoading()
					this.$message({
						message: res.msg,
						type: "success",
						duration: 1000,
						onClose: () => {
							this.getDataList()
							this.dialogVisible_fhxx = false
							this.dataForm_fhxx = {
								id: '',
								content: '',
								thumb: ''
							}
						}
					});
				})
			},
			submitForm_czq() {
				this.$refs['dataForm_czq'].validate((valid) => {
					if (valid) {
						if (!this.dataForm_czq.thumb) {
							return this.$message.error("请上传合同文件！")
						}
						this.$loading()
						this.$http.post('/api/order/coupons', this.dataForm_czq).then(res => {
							this.$closeLoading()
							this.$store.dispatch("userCzqAction")
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 2000,
								onClose: () => {
									this.getDataList()
									this.handleClose_czq()
									this.$refs.dataForm_czq.resetFields()
									this.dataForm_czq.id=''
								}
							});
						})
					} else {
						return false;
					}
				});
			},
			submitForm_czq2() {
				this.$refs['dataForm_czq'].validate((valid) => {
					if (valid) {
						if (!this.dataForm_czq.thumb) {
							return this.$message.error("请上传合同文件！")
						}
						this.$loading()
						let data = {
							id: this.dataForm_czq.id,
							hetong_num: this.dataForm_czq.hetong_num,
							fuwu_num: this.dataForm_czq.fuwu_num,
							coupons_num:this.dataForm_czq.coupons_num,
							thumb: this.dataForm_czq.thumb,
							is_post:1
						}
						this.$http.post('/api/order/edit_coupons', data).then(res => {
							this.$closeLoading()
							this.$store.dispatch("userCzqAction")
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.getDataList()
									this.handleClose_czq()
									this.$refs.dataForm_czq.resetFields()
									this.dataForm_czq.id=''
								}
							});
						})
					} else {
						return false;
					}
				});
			},
			//作废
			zuofei(row) {
				this.$confirm('作废后将终止该需求订单，申请创制券的将返还使用额度，请谨慎操作！', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {

					this.$prompt('作废原因', '提示', {
						showInput: true,
						inputType: 'textarea',
						inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
						inputErrorMessage: '作废原因不能为空!',
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then((param) => {
						this.$loading()
						this.$http.post('/api/order/reject', {
							id: row.order_id,
							cause: param.value,
							type: '-4',
						}).then(res => {
							this.$closeLoading()
							this.$message.success(res.msg)
							this.getDataList()
						})
					}).catch(() => {});
				}).catch(() => {});
			},
			ok_sh(row) {
				this.$confirm('是否确认收货？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {

					this.$loading()
					this.$http.post('api/order/shouhuo', {
						id: row.order_id,
						value: 9
					}).then(res => {
						this.$closeLoading()
						this.$message({
							message: res.msg,
							type: "success",
							duration: 1500,
							onClose: () => {
								this.getDataList()
							}
						});
					})

				}).catch(() => {});
			},
			formatter(row) {
				for (let i = 0; i < this.stateList.length; i++) {
					if (this.stateList[i].status === row.status) {
						return this.stateList[i].title
					}
				}
			},
			exports() {

			},
		},
		created() {
			this.getStateList()
			this.getFactList()
		}
	}
</script>
<style lang="scss" scoped>
	.table {
		border-collapse: collapse;

		th {
			background: #F6F7FA;
			border: 1px solid #ebeef5;
			border-collapse: collapse;
			padding: 10px 0;
			text-align: center;
			line-height: 20px;
			font-size: 14px;
			font-weight: 400;
			color: #333333;
		}

		td {
			border: 1px solid #ebeef5;
			border-collapse: collapse;
			padding: 5px 0;
			text-align: center;
			line-height: 20px;
			font-size: 14px;
			font-weight: 400;
			color: #333333;
		}
	}

	.el-table_1_column_11 .cell {
		display: block !important;
	}

	/deep/ .el-table_1_column_11 .cell {
		display: block !important;
	}
</style>